﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Radio_Streamer;

namespace Shoutcast
{
    public partial class MainPage : PhoneApplicationPage
    {
        private RadioStream shoutcastStream;
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void StartStreamingButton_Click(object sender, RoutedEventArgs e)
        {
            (sender as Button).IsEnabled = false;
            shoutcastStream = new RadioStream(UrlTextBox.Text);
            shoutcastStream.StreamSetupComplete += new RadioStream.StreamSetupCompleteHandler(shoutcastStream_StreamSetupComplete);
        }

        void shoutcastStream_StreamSetupComplete(object sender, EventArgs args)
        {
            //Prevent cross-thread issues
            System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                ShoutcastPlayer.SetSource(shoutcastStream);
                this.StationName.Text += shoutcastStream.StationName;
                this.Genre.Text += shoutcastStream.Genre;
                this.Bitrate.Text += shoutcastStream.BitRate;
                this.StationName.Visibility = System.Windows.Visibility.Visible;
                this.Genre.Visibility = System.Windows.Visibility.Visible;
                this.Bitrate.Visibility = System.Windows.Visibility.Visible;
            });
        }
    }
}